home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: twisto.eng.hou.compaq.com!news
- From: Cindy McGee <cindym@bangate.compaq.com>
- Subject: Q: ifstream/memory problem?
- Message-ID: <3173C9D4.7480@bangate.compaq.com>
- Sender: news@twisto.eng.hou.compaq.com (System Administrator)
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.0 (Win95; I)
- Content-Type: text/plain; charset=us-ascii
- Organization: Compaq Computer Corporation
- Date: Tue, 16 Apr 1996 16:24:52 GMT
- X-Nntp-Posting-Host: 172.18.220.53
- Content-Transfer-Encoding: 7bit
-
- I may have an ifstream problem, a memory problem, or a combination thereof, and my reference
- material isn't detailed enough on iostream behavior. I've outlined the problem below. Any ideas?
-
- In the constructor of a large object I am instantiating a list of smaller objects whose member
- variables are filled with information read from a text file. Later, when accessing the larger
- object via member functions, the object exhibits strange behavior. Inside of
- TheApp->pLargeOb->Foo(), watching TheApp->pLargeOb->m_iXxx gives a value of 1 but this->m_iXxx is
- uninitialized.
-
- Running Bounds Checker on the app shows several errors. I get an invalid argument error in the
- streambuf's destructor on a delete statement, a memory overrun in the filebuf's scalar deleting
- destructor, and another invalid argument error in the filebuf's scalar deleting destructor.
- Finally, I get a dynamic memory overrun where the large object is instantiated via new.
-
- A code snippet is below.
-
- (I hope this posts -- it's my second attempt!)
-
-
- Thanks,
-
- Cindy McGee
- -----------------------
- cindym@bangate.compaq.com
-
- ===========================================================
- LargeOb::LargeOb()
- {
- ...
- m_pListSmall = new SmallList("data.txt");
- ...
- }
-
- void SmallList::Foo(char* szFileName)
- {
- char sz[255];
- ...
- ifstream file(szFileName);
-
- if (!file)
- ... // error handling
- else
- {
- int iNumElems = 0;
- file >> iNumElems;
- ...
-
- file >> sz;
- for (int i = 0; i < iNumElems; i++)
- {
- pNewElem = new Elem();
- if ('*' == sz[0])
- {
- file.ignore(1000,'/');
- file >> sz;
- }
-
- if (0 == strcmp(sz,"Field1"))
- {
- file.eatwhite();
- file.getline(sz,255);
- pNewElem->SetField1(sz);
- file >> sz;
- }
-
- .. // many more string compares, sets, and extractions
-
- Append(*pNewElem); // ptr copy only
- }
- }
- }
-